package com.shd.edanpei.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.ui.adapter.NeedAdapter;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.base.rxbus.RxBus;
import com.shd.edanpei.bean.ListBean;
import com.shd.edanpei.presenter.contract.SelectContract;
import com.shd.edanpei.presenter.SelectPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2018/8/16.
 * 多数据选择
 */
public class SelectActivity extends BaseActivity<SelectPresenter>
        implements SelectContract.SelectIView {

    public static final int DONE_SELECT = 100;

    @BindView(R.id.headline)
    TextView tvHeadline;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private NeedAdapter mAdapter;
    private int type;

    @Override
    protected int setLayout() {
        return R.layout.activity_select;
    }

    @Override
    protected SelectPresenter bindPresenter() {
        return new SelectPresenter(this);
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        Bundle extras = getIntent().getExtras();
        String title = extras.getString(Constant.TITLE);
        type = extras.getInt(Constant.TAG);
        String data = extras.getString(Constant.DATA);
        tvHeadline.setText(title);
        mAdapter = new NeedAdapter(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(mAdapter);
        mPresenter.getListData(type, data);
    }

    @Override
    protected void initListener() {

    }

    @OnClick(R.id.iv_headline_back)
    void onBack(){
        finish();
    }

    @OnClick(R.id.tv_submit)
    void onClickSubmit() {
        ListBean listBean = new ListBean(type, mAdapter.getData());
        RxBus.get().send(DONE_SELECT, listBean);
        finish();
    }

    @Override
    public NeedAdapter getAdapter() {
        return mAdapter;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
